<template> 
<div id="stuPC">
  
 <el-upload
  class="avatar-uploader"
  action="http://125.210.160.93:8080/SmEdu/pass/stu/update"
  :show-file-list="false"
  name=files
  :before-upload="beforeAvatarUpload"
  :data='questObj'
  :on-success="handleAvatarSuccess"
  >
  <img v-if="imageUrl" :src="imageUrl" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload> 

</div>
</template>

<script>
  export default {
    data() {
      return {
        imageUrl: '',
        questObj:{
          studId:''
        },
      };
    },
    methods: {
      handleAvatarSuccess(res, file) {
        console.log(res);
        console.log(file);
        
        
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        //console.log('h1h1h1h1h1');
        var hh=document.getElementsByTagName('h6');
         //console.log(hh);
         var h1=document.getElementsByTagName('h6')[0].innerHTML;
         //console.log(parseInt(h1));
         this.questObj.studId=parseInt(h1);
        // console.log('h2h2h2h2');
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      
              
    },
    
  }
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 2.8733rem;
    height: 2.8733rem;
    line-height: 2.8733rem;
    text-align: center;
  }
  .avatar {
    width: 2.8733rem;
    height: 2.8733rem;
    display: block;
  }
  .el-message-box{
    width:90% !important;
}
.el-message-box__message h6{
  color:#fff !important;
}
</style>